﻿function summit_delete_model(ID) {
    $("#dialog-confirm").removeClass('hide').dialog({
        resizable: false,
        modal: true,
        title: "<div class='widget-header'><h4 class='smaller'><i class='icon-warning-sign red'></i>删除模型</h4></div>",
        title_html: true,
        buttons: [
            {
                html: "<i class='icon-trash'></i>&nbsp; 删除",
                "class": "btn btn-danger btn-xs",
                click: function () {
                    var s = "";
                    s = $.ajax({
                        type: "POST",
                        url: "AjaxAction.ashx",
                        data: {
                            dowhat: "delete_model",
                            UserName: $("#UserName").val(),
                            UserIP: $("#UserIP").val(),
                            ID: ID
                        },
                        async: false
                    }).responseText;
                    if (s == "success") {
                        window.location.href = "Default.aspx" + location.search;
                    }
                }
            }
            ,
            {
                html: "<i class='icon-remove'></i>&nbsp; 取消",
                "class": "btn btn-xs",
                click: function () {
                    $(this).dialog("close");
                }
            }
        ]
    });
};

function summit_add_model() {
    $("#Name").val(""); $("#AdminDir").val(""); $("#WebDir").val(""); $("#TableName").val(""); $("#Remark").val("");
    $(".alert-success").remove(); $(".alert-danger").remove();
    var dialog = $("#dialog-message").removeClass('hide').dialog({
        modal: true,
        title: "<div class='widget-header widget-header-small'><h4 class='smaller'><i class='icon-ok'></i>添加模型新项</h4></div>",
        title_html: true,
        buttons: [
            {
                text: "添加",
                "class": "btn btn-primary btn-xs",
                click: function () {
                    var s = "";
                    s = $.ajax({
                        type: "POST",
                        url: "AjaxAction.ashx",
                        data: {
                            dowhat: "add_model",
                            Name: $("#Name").val(),
                            AdminDir: $("#AdminDir").val(),
                            WebDir: $("#WebDir").val(),
                            TableName: $("#TableName").val(),
                            Remark: $("#Remark").val(),
                            UserName: $("#UserName").val(),
                            UserIP: $("#UserIP").val()
                        },
                        async: false
                    }).responseText;
                    if (s == "success") {
                        $(".alert-success").remove(); $(".alert-danger").remove(); $("#UserName").after("<div class='alert alert-block alert-success'><button type='button' class='close' data-dismiss='alert'><i class='icon-remove'></i></button><small><strong><i class='icon-ok'></i>&nbsp;&nbsp;&nbsp;&nbsp;添加成功</strong> </small></div>");
                        $("#Name").val(""); $("#AdminDir").val(""); $("#WebDir").val(""); $("#TableName").val(""); $("#Remark").val("");
                    }
                    else { $(".alert-success").remove(); $(".alert-danger").remove(); $("#UserName").after("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'><i class='icon-remove'></i></button><small><strong><i class='icon-remove'></i>&nbsp;&nbsp;&nbsp;&nbsp;错误!</strong> 除了备注，所有信息不能为空。</small></div>"); }
                }

            },
            {
                text: "取消",
                "class": "btn btn-xs",
                click: function () {
                    $(this).dialog("close");
                }
            }
        ]
    });

    /**
    dialog.data( "uiDialog" )._title = function(title) {
        title.html( this.options.title );
    };
    **/
}


function summit_update_model(ID, Name, AdminDir, WebDir, TableName, Remark) {
    $("#Name").val(Name); $("#AdminDir").val(AdminDir); $("#WebDir").val(WebDir); $("#TableName").val(TableName); $("#Remark").val(Remark);
    $(".alert-success").remove(); $(".alert-danger").remove();
    var dialog = $("#dialog-message").removeClass('hide').dialog({
        modal: true,
        title: "<div class='widget-header widget-header-small'><h4 class='smaller'><i class='icon-check green'></i>编辑模型现有项</h4></div>",
        title_html: true,
        buttons: [
            {
                text: "修改",
                "class": "btn btn-success btn-xs",
                click: function () {
                    var s = "";
                    s = $.ajax({
                        type: "POST",
                        url: "AjaxAction.ashx",
                        data: {
                            dowhat: "update_model",
                            ID: ID,
                            Name: $("#Name").val(),
                            AdminDir: $("#AdminDir").val(),
                            WebDir: $("#WebDir").val(),
                            TableName: $("#TableName").val(),
                            Remark: $("#Remark").val(),
                            UserName: $("#UserName").val(),
                            UserIP: $("#UserIP").val()
                        },
                        async: false
                    }).responseText;
                    if (s == "success") {
                        $(".alert-success").remove(); $(".alert-danger").remove(); $("#UserName").after("<div class='alert alert-block alert-success'><button type='button' class='close' data-dismiss='alert'><i class='icon-remove'></i></button><small><strong><i class='icon-ok'></i>&nbsp;&nbsp;&nbsp;&nbsp;修改成功</strong> </small></div>");

                    }
                    else { $(".alert-success").remove(); $(".alert-danger").remove(); $("#UserName").after("<div class='alert alert-danger'><button type='button' class='close' data-dismiss='alert'><i class='icon-remove'></i></button><small><strong><i class='icon-remove'></i>&nbsp;&nbsp;&nbsp;&nbsp;错误!</strong> 除了备注，所有信息不能为空。</small></div>"); }
                }

            },
            {
                text: "取消",
                "class": "btn btn-xs",
                click: function () {
                    $(this).dialog("close");
                }
            }
        ]
    });

    /**
    dialog.data( "uiDialog" )._title = function(title) {
        title.html( this.options.title );
    };
    **/
}